//========encoding:utf-8=========
/*
 * @describe:  三目运算符
 * @author:mhao
 * @copyright:chinasoft.cn
 * @date:2020年3月31日   下午11:23:45
 */
package edu.chinasoft.service;

import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import edu.chinasoft.domain.Application;
import edu.chinasoft.domain.Approval;
import edu.chinasoft.domain.PageUnitForApplication;
import edu.chinasoft.domain.Role;
import edu.chinasoft.domain.User;
import edu.chinasoft.mapper.ApprovalMapper;
@Service("approvalService")
public class ApprovalServiceImp implements ApprovalService {
	@Autowired
	@Qualifier("approvalMapper")
	private ApprovalMapper approvalMapper;
	private Logger logger = LoggerFactory.getLogger(ApprovalServiceImp.class);
	@Transactional(readOnly=false,propagation=Propagation.REQUIRED)
	@Override
	public boolean insertApproval(Approval approval) {
		// TODO Auto-generated method stub
		 logger.info("ApprovalServiceImp>>>insertApproval start ……");
		 boolean result_approval=false;
		 boolean result_application=false;
		 boolean result_item=false;
		 if (approval.getNextApprovalUser()==null) {
			 //驳回  没有下一级审批者
			result_approval = approvalMapper.insertApproval(approval);
			result_application = approvalMapper.updateApplicationState(approval);
			result_item = approvalMapper.insertItem(approval);
		}else {
			result_approval=approvalMapper.insertApproval(approval);
			result_item=approvalMapper.insertItem(approval);
			result_application=true;
		}
		logger.info("ApprovalServiceImp>>>insertApproval end ……");
		return result_application&&result_approval&&result_item;
	}


}
